package com.itheima.web.servlet;

import com.itheima.domain.User;
import com.itheima.service.UserSeriver;
import com.itheima.service.impl.UserSeriverImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/userFindServlet")
public class UserFindServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.获取修改id
        String id = request.getParameter("id");

        //2. 调用service查询
        UserSeriver service = new UserSeriverImpl();
        User user = service.findById(id);

        //3. 将user添加到请求域中, 转发到update.jsp 回显
        request.setAttribute("u",user);
        request.getRequestDispatcher("/update.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
